package com.sunfeng.chap5.selectkey;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

/**
 * 不同的通道注册到相同的选择器，返回的 Selection Key 不是同一个对象
 */
public class Test9_1 {
    public static void main(String[] args) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        ServerSocketChannel serverSocketChannel1 = ServerSocketChannel.open();
        Selector selector = Selector.open();

        SelectionKey selectionKey = serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
        System.out.println(selectionKey.hashCode() + "   " + selectionKey);
        SelectionKey selectionKey1 = serverSocketChannel1.register(selector, SelectionKey.OP_ACCEPT);
        System.out.println(selectionKey1.hashCode() + "   " + selectionKey1);
        serverSocketChannel.close();
        serverSocketChannel1.close();
    }
}
